package GUI;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Member extends JFrame {

	private JPanel contentPane;
	private JTextField txtName;
	private JTextField txtSurname;
	private JTextField txtAddress;
	private JTextField txtPhone;
	private JTextField txtCpr;
	private JTextField txtDiscount;
	private AssignToOrder a;
	private Success su;

	/**
	 * Create the frame.
	 */
	public Member(String s, String pc){
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 245, 245);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		if(s.equals("new"))
		{
			setTitle("Create New Member");
		}
		else
		{
			setTitle("Manage Member");
		}
		
		
		
		if(pc.equals("p"))
		{
			JLabel lblMemberName = new JLabel("Name: ");
			lblMemberName.setBounds(10, 11, 46, 14);
			contentPane.add(lblMemberName);
			
			txtName = new JTextField();
			txtName.setBounds(100, 8, 121, 20);
			contentPane.add(txtName);
			txtName.setColumns(10);
			
			JLabel lblSurname = new JLabel("Surname:");
			lblSurname.setBounds(10, 36, 80, 14);
			contentPane.add(lblSurname);
			
			txtSurname = new JTextField();
			txtSurname.setColumns(10);
			txtSurname.setBounds(100, 33, 121, 20);
			contentPane.add(txtSurname);
			
			JLabel lblCpr = new JLabel("CPR:");
			lblCpr.setBounds(10, 111, 80, 14);
			contentPane.add(lblCpr);
			
			txtCpr = new JTextField();
			txtCpr.setColumns(10);
			txtCpr.setBounds(100, 108, 121, 20);
			contentPane.add(txtCpr);
		}
		else
		{
			JLabel lblName = new JLabel("Name:");
			lblName.setBounds(10, 36, 80, 14);
			contentPane.add(lblName);
			
			txtName = new JTextField();
			txtName.setColumns(10);
			txtName.setBounds(100, 33, 121, 20);
			contentPane.add(txtName);
			
			JLabel lblCpr = new JLabel("CVR:");
			lblCpr.setBounds(10, 111, 80, 14);
			contentPane.add(lblCpr);
			
			JTextField txtCvr = new JTextField();
			txtCvr.setColumns(10);
			txtCvr.setBounds(100, 108, 121, 20);
			contentPane.add(txtCvr);
		}
		
		
		JLabel lblAddress = new JLabel("Address:");
		lblAddress.setBounds(10, 61, 80, 14);
		contentPane.add(lblAddress);
		
		txtAddress = new JTextField();
		txtAddress.setColumns(10);
		txtAddress.setBounds(100, 58, 121, 20);
		contentPane.add(txtAddress);
		
		JLabel lblPhone = new JLabel("Phone:");
		lblPhone.setBounds(10, 86, 80, 14);
		contentPane.add(lblPhone);
		
		txtPhone = new JTextField();
		txtPhone.setColumns(10);
		txtPhone.setBounds(100, 83, 121, 20);
		contentPane.add(txtPhone);
		
		
		JLabel lblDiscount = new JLabel("Discount:");
		lblDiscount.setBounds(10, 136, 80, 14);
		contentPane.add(lblDiscount);
		
		txtDiscount = new JTextField();
		txtDiscount.setColumns(10);
		txtDiscount.setBounds(100, 133, 46, 20);
		contentPane.add(txtDiscount);
		
		JLabel label = new JLabel("%");
		label.setBounds(148, 139, 17, 14);
		contentPane.add(label);
		
		JButton btnNewButton = new JButton("Add");
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				a=new AssignToOrder("dis", "dis");
				a.setVisible(true);
			}
		});
		btnNewButton.setBounds(161, 133, 60, 20);
		contentPane.add(btnNewButton);
		
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				MainMenu.getInstance().setVisible(true);
				dispose();
			}
		});
		btnCancel.setBounds(10, 172, 90, 23);
		contentPane.add(btnCancel);
		
		if(s.equals("new"))
		{
			JButton btnSave = new JButton("Save");
			btnSave.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					//???? SABIN
					su = new Success("cr", false);
					su.setVisible(true);
					dispose();
				}
			});
			btnSave.setBounds(125, 172, 96, 23);
			contentPane.add(btnSave);
		}
		else
		{
			JButton btnSave = new JButton("Save");
			btnSave.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					//???? SABIN
					su = new Success("mng", false);
					su.setVisible(true);
					dispose();
				}
			});
			btnSave.setBounds(125, 172, 96, 23);
			contentPane.add(btnSave);
		}
	}
}
